package com.example.vue20220225.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.example.vue20220225.model.Power;
import com.example.vue20220225.model.Role;
import com.example.vue20220225.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

//   userinfo 实体类 映射表
public interface UserDao extends BaseMapper<UserInfo> {

    //  这里面跟xml文件  写法一样
    @Select("select * from user_info where username=#{username} and password=#{password}")
    public UserInfo login(UserInfo userInfo);

    //  queryPowerlist  方法名
    List<Power> queryPowerlist(UserInfo userInfo);

    //参数加上@Param(Constants.WRAPPER),xml里加上${ew.customSqlSegment}可以实现复杂条件检索查询
    IPage<UserInfo> queryUserlist(IPage<UserInfo> page, @Param(Constants.WRAPPER) Wrapper<UserInfo> wrapper);

    @Select("select * from role")
    List<Role> queryroles();

    @Update("update user_role set role_id = #{roleId} where user_id = #{id}")
    Integer editUserRoll(UserInfo userInfo);

    @Select("select count(id) from user_role where user_id = #{id}")
    Integer checkUserRole(UserInfo userInfo);

    @Insert("insert into user_role values(null,#{id},#{roleId})")
    Integer insertUserRoll(UserInfo userInfo);

    //参数加上@Param(Constants.WRAPPER),xml里加上${ew.customSqlSegment}可以实现复杂条件检索查询
    IPage<Role> queryrolespower(IPage<Role> page, @Param(Constants.WRAPPER) Wrapper<UserInfo> wrapper);

    @Delete("delete from user_role where user_id = #{id}")
    Integer deleteUserRole(Integer id);
}
